package com.woniuxy.microaftersaleserver.customservicemag.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.microaftersaleserver.customservicemag.service.ICustomService;
import com.woniuxy.microcommonserver.bean.aftersales_cyx.CustomService;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import com.woniuxy.microcommonserver.pageHelper.TableResult;
import com.woniuxy.microcommonserver.res.ResultMsg;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/customService")
@RestController
public class CustomServiceController {

    @Resource
    private ICustomService customServiceImpl;

    @PostMapping(value = "/add",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg addCustomService(CustomService customService){
        customServiceImpl.addCustomerService(customService);
        return new ResultMsg(200,"添加成功",null);
    }

    @PutMapping(value = "/delete",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg deleteCustomService(int id){
       customServiceImpl.deleteCustomService(id);
        return new ResultMsg(200,"删除成功",null);
    }

    /**
     * 分页查询所有客服人员信息
     * @param request
     * @param customService
     * @return
     */
    @GetMapping (value = "/select",produces = MediaType.APPLICATION_JSON_VALUE)
    public TableResult<CustomService> getCustomService( PageRequest request, CustomService customService){
        System.out.println(request+"=================");
        System.out.println(customService+"=================");
        PageInfo<CustomService> pages= customServiceImpl.findByPage(request,customService);
        System.out.println(pages);
        return new TableResult<>(pages.getTotal(),pages.getList());
    }

   /* @GetMapping(value = "/find",produces = MediaType.APPLICATION_JSON_VALUE)
    public CustomService findCusInfo(CustomService customService){
        customServiceImpl.findByParams(customService);

    }*/

    @PutMapping(value = "/update",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg updateCustomService(CustomService customService){
        customServiceImpl.updateCustomService(customService);
         return new ResultMsg(200,"修改成功",null);
    }
}
